package com.qianyucc.guishi.model.vo;

import cn.hutool.core.date.*;
import com.qianyucc.guishi.global.*;
import com.qianyucc.guishi.model.enums.*;
import lombok.*;
import org.h2.api.*;

import java.time.*;
import java.util.*;

import static com.qianyucc.guishi.config.Constant.DATE_TIME_PATTERN;

/**
 * @author lijing
 * @date 2019-10-12 10:40
 * @description 封装返回信息
 */
@Data
@Builder
public class RespDataVO {
    private Integer code;
    private String msg;
    private String timestamp;
    private Object data;

    public static RespDataVO ok(String message, Object data) {
        return RespDataVO.builder()
                .code(2000)
                .msg(message)
                .data(data)
                .timestamp(DateUtil.format(new Date(), DATE_TIME_PATTERN))
                .build();
    }

    public static RespDataVO ok(String message) {
        return RespDataVO.builder()
                .code(2000)
                .msg(message)
                .timestamp(DateUtil.format(new Date(), DATE_TIME_PATTERN))
                .build();
    }

    public static RespDataVO error(String message) {
        return RespDataVO.builder()
                .code(5000)
                .msg(message)
                .timestamp(DateUtil.format(new Date(), DATE_TIME_PATTERN))
                .build();
    }

    public static RespDataVO create(GuiShiException e) {
        return RespDataVO.builder()
                .code(e.getCode())
                .msg(e.getMessage())
                .timestamp(DateUtil.format(new Date(), DATE_TIME_PATTERN))
                .build();
    }
}

